# 使用正则表达式正确爬取网页的标题title
import re
import requests

url = "https://www.kanzhun.com/rank_p/?ka=index-icon-click"

ua = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
}

try:
    req = requests.get(url, headers=ua)
except:
    print("网络地址错误或网络信号不佳")


title_pattern = r'<title data-react-helmet="true">(.*?)</title>'

result = re.findall(title_pattern, req.text)

print("标题内容：" + result[0])